// pages/doctor-my-course/doctor-my-course.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    doctorId: '',      // 医生id
    pagesize: 6,      // 显示多少行
    page: 0,          // 页数
    imgUrl: app.globalData.imgUrl, //请求接口图片路径
    localImg: app.globalData.staticimgUrl,  // 本地图片
    list: '',
    num: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCourseList();
  
  },

  // 获取课程列表
  getCourseList(){
    app.showLoading();
    const that = this;
    const { pagesize, page} = this.data;
    const param = {
      doctorId: wx.getStorageSync('userid'),
      pagesize,
      page
    };
    app.request({
      url: "/doctor/doctor/getDoctorCourse",
      data: param,
      success: function (res) {
        wx.hideLoading();
        that.setData({
          list: res.data,
          num:res.page.total
        });
      },
      fail: function (res) {
        
      }
    });
  },


  /**
 * 页面上拉触底事件的处理函数
 */
  onReachBottom: function (e) {
    app.showLoading();
    this.setData({
      pagesize: this.data.pagesize + 5
    })
    if (this.data.list.length == this.data.num) {
      wx.showToast({
        title: '没有更多了哦~',
        icon: 'none',
        duration: 1000
      });
    } else {
      this.getCourseList();
    }

  },
  //进入详情
  entryCourse(e) {
    const id = e.currentTarget.dataset.id;
    const classify = e.currentTarget.dataset.classify;
    const obj = {
      id,
      classify
    }
    wx.navigateTo({
      url: "../doctor-train-details/doctor-train-details?obj=" + JSON.stringify(obj)
    });
  },

})